/*!
 *     COPYRIGHT NOTICE
 *     Copyright (c) 2013,山外科技
 *     All rights reserved.
 *     技术讨论：山外论坛 http://www.vcan123.com
 *
 *     除注明出处外，以下所有内容版权均属山外科技所有，未经允许，不得用于商业用途，
 *     修改内容时必须保留山外科技的版权声明。
 *
 * @file       main.c
 * @brief      山外K60 平台主程序
 * @author     山外科技
 * @version    v5.2
 * @date       2014-11-03
 */

#include "common.h"
#include "include.h"

float pwmc=0;

char ch;

//uint16 K1,K2,K3,K4,qd=1,distance=30;
//uint8 ax3=0,ax4=0;

//uint8 head[]={
//0x00,0x18,0x28,0x48,0x88,0x08,0xF8,0x08,0x88,0x48,0x28,0x18,0x00,0x00,0x00,0x00,
//0xC0,0x00,0xF0,0x00,0xFC,0x00,0x00,0xE0,0x00,0xE0,0x00,0x00,0x00,0x00,0xE0,0x20,
//0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x90,0x90,0xF0,0x00,0x00,
//0x00,0x90,0x90,0x90,0xF0,0x00,0x90,0x90,0x90,0xF0,0x00,0xF0,0x60,0x80,0x00,0x80,
//0x60,0xF0,0x00,0x00,0x80,0x60,0x10,0x00,0xF0,0x90,0x90,0x90,0x00,0x00,0x00,0x00,
//0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,0xE0,
//0xE0,0xFF,0xFF,0xFF,0x03,0x03,0x13,0x13,0x13,0x13,0xF3,0x03,0x03,0x03,0x13,0x13,
//0x13,0xF3,0x03,0x03,0x03,0x73,0x53,0x73,0x83,0xC3,0x63,0x03,0x03,0xFF,0xFF,0x80,
//0x80,0x80,0x80,0x80,0x81,0x9F,0x81,0x80,0x80,0x80,0x80,0x9C,0x80,0x9F,0x80,0x9F,
//0x80,0x9F,0x80,0x9F,0x80,0x80,0x81,0x81,0x8F,0x81,0x81,0x80,0x80,0x8F,0x88,0x88,
//0x89,0x8F,0x81,0x80,0x80,0x80,0x80,0x80,0x80,0x87,0x84,0x84,0x84,0x80,0x84,0x80,
//0x84,0x84,0x84,0x87,0x80,0x84,0x84,0x84,0x87,0x80,0x87,0x80,0x81,0x86,0x81,0x80,
//0x87,0x80,0x86,0x81,0x80,0x80,0x80,0x84,0x84,0x84,0x87,0x80,0x80,0x80,0x80,0x80,
//0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x87,0x87,0x87,0x87,
//0xFF,0xFF,0xFF,0xC0,0xC0,0xC9,0xC9,0xC9,0xC9,0xCF,0xC0,0xC0,0xC0,0xCF,0xC9,0xC9,
//0xC9,0xC0,0xC0,0xC0,0xCC,0xC4,0xC7,0xC1,0xCE,0xCA,0xCE,0xC0,0xFF,0xFF,/*"E:\Desktop\无标题1.bmp",0*/
//};





/************ADC按键函数*************/
//void keyt()
//{
//
//
//
//    K2=adc_once (ADC1_SE10,ADC_8bit);
//    K1=adc_once (ADC1_SE11,ADC_8bit);
//    K3=adc_once (ADC1_SE12,ADC_8bit);
//    K4=adc_once (ADC1_SE13,ADC_8bit);
//    if(qd!=0)
//    {
//      if(K3==0&&ax3==0)
//      {
//        distance++;
//        ax3=1;
//        if(distance<=30) { distance=60;}
//        if(distance>=60) { distance=30;}
//      }
//      if(K3>0) ax3=0;
//      if(K4==0&&ax4==0)
//      {
//        distance--;
//        ax4=1;
//        if(distance<30) { distance=60;}
//        if(distance>60) { distance=30;}
//      }
//      if(K4>0) ax4=0;
//
//      angle_set=ww[distance-30];
//    }
//
//    if(K1==0) qd=0;    //break;
//
//
//}

/*!
 *  @brief      main函数
 *  @since      v5.2
 *  @note       FTM PWM 电机驱动测试
 */

void main(void)
{

//    adc_init (ADC1_SE10);
//    adc_init (ADC1_SE11);
//    adc_init (ADC1_SE12);
//    adc_init (ADC1_SE13);                               //按键初始化
//    printf("\n*****FTM PWM 电机测试*****\n");
      mk60int();

                                                    // FTM0_PRECISON 配置 为 100 ，即占空比 为 100%
                                                    // port_cfg.h 里 配置 FTM0_CH3 对应为 PTA6
//    gpio_init(PTD15,GPO,0);                         // 使能端 输入为 0
    //led_init(LED1);

    //山外的电机驱动模块，经过 MOS 管 反相隔离。
    //K60 输出 PWM 为 100% ，实际接入 电机驱动就是 0%
    //K60 输出 使能端 为 低电平，实际接入 电机驱动 使能端就是 高电平

    while(1)
    {
//     for(dj=1000;dj<2000;dj++)
//     {

//        lptmr_delay_ms(50);
//     }
//        if(key_check(KEY_U) == KEY_DOWN)
//        {
//            dj+=0.01;
//            control_actuator(dj);
//        }
//        if(key_check(KEY_D) == KEY_DOWN)
//        {
//            dj-=0.01;
//            control_actuator(dj);
//        }

    }
}


void PIT0_IRQHandler(void)
{

//    Draw_BMP(0,0,127,1,head);
//    OLED_P14x16Str(36,2,"中国联通");
//    //OLED_P14x16Str(0,4,"当前占空比：");
//    Display_number7(0,5,(int16)(pwmc*100));
//    //OLED_P6x8Str(102,5,"%");
//    OLED_P14x16Str(0,6,"菜单");
//    OLED_P8x16Str(57,6,"OK");
//    OLED_P14x16Str(85,6,"电话簿");
//    PIT_Flag_Clear(PIT0);       //清中断标志位
//    uint8 temp=(uint8)ch;
    OLED_P8x16Str(2,0,"one");
//    OLED_P8x16Str(0,0,&temp);
    if(uart_querychar(UART4,&ch))
    {
        uart_putchar (UART4, ch);
    }
}

//void uart3_handler(void)
//{
//    char ch;
//
//    if(uart_query    (UART3) == 1)   //接收数据寄存器满
//    {
//        //用户需要处理接收数据
//        uart_getchar   (UART3, &ch);                    //无限等待接受1个字节
//        uart_putchar   (UART3 , ch);                    //发送字符串
//    }
//}